

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>federatedml.param.boosting_tree_param &mdash; FATE 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> FATE
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">FATE</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>federatedml.param.boosting_tree_param</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for federatedml.param.boosting_tree_param</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>

<span class="c1">#</span>
<span class="c1">#  Copyright 2019 The FATE Authors. All Rights Reserved.</span>
<span class="c1">#</span>
<span class="c1">#  Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1">#  you may not use this file except in compliance with the License.</span>
<span class="c1">#  You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1">#      http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1">#  Unless required by applicable law or agreed to in writing, software</span>
<span class="c1">#  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1">#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1">#  See the License for the specific language governing permissions and</span>
<span class="c1">#  limitations under the License.</span>
<span class="c1">#</span>

<span class="kn">from</span> <span class="nn">federatedml.param.base_param</span> <span class="k">import</span> <span class="n">BaseParam</span>
<span class="kn">from</span> <span class="nn">federatedml.param.encrypt_param</span> <span class="k">import</span> <span class="n">EncryptParam</span>
<span class="kn">from</span> <span class="nn">federatedml.param.encrypted_mode_calculation_param</span> <span class="k">import</span> <span class="n">EncryptedModeCalculatorParam</span>
<span class="kn">from</span> <span class="nn">federatedml.param.cross_validation_param</span> <span class="k">import</span> <span class="n">CrossValidationParam</span>
<span class="kn">from</span> <span class="nn">federatedml.param.predict_param</span> <span class="k">import</span> <span class="n">PredictParam</span>
<span class="kn">from</span> <span class="nn">federatedml.util</span> <span class="k">import</span> <span class="n">consts</span>
<span class="kn">import</span> <span class="nn">copy</span>


<div class="viewcode-block" id="ObjectiveParam"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.boosting_tree_param.ObjectiveParam">[docs]</a><span class="k">class</span> <span class="nc">ObjectiveParam</span><span class="p">(</span><span class="n">BaseParam</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Define objective parameters that used in federated ml.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    objective : None or str, accepted None,&#39;cross_entropy&#39;,&#39;lse&#39;,&#39;lae&#39;,&#39;log_cosh&#39;,&#39;tweedie&#39;,&#39;fair&#39;,&#39;huber&#39; only,</span>
<span class="sd">                None in host&#39;s config, should be str in guest&#39;config.</span>
<span class="sd">                when task_type is classification, only support cross_enctropy,</span>
<span class="sd">                other 6 types support in regression task. default: None</span>

<span class="sd">    params : None or list, should be non empty list when objective is &#39;tweedie&#39;,&#39;fair&#39;,&#39;huber&#39;,</span>
<span class="sd">             first element of list shoulf be a float-number large than 0.0 when objective is &#39;fair&#39;,&#39;huber&#39;,</span>
<span class="sd">             first element of list should be a float-number in [1.0, 2.0) when objective is &#39;tweedie&#39;</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">objective</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">objective</span> <span class="o">=</span> <span class="n">objective</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">params</span> <span class="o">=</span> <span class="n">params</span>

<div class="viewcode-block" id="ObjectiveParam.check"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.boosting_tree_param.ObjectiveParam.check">[docs]</a>    <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">task_type</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">objective</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">True</span>

        <span class="n">descr</span> <span class="o">=</span> <span class="s2">&quot;objective param&#39;s&quot;</span>

        <span class="k">if</span> <span class="n">task_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">consts</span><span class="o">.</span><span class="n">CLASSIFICATION</span><span class="p">,</span> <span class="n">consts</span><span class="o">.</span><span class="n">REGRESSION</span><span class="p">]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">objective</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">objective</span><span class="p">,</span>
                                                   <span class="p">[</span><span class="s2">&quot;cross_entropy&quot;</span><span class="p">,</span> <span class="s2">&quot;lse&quot;</span><span class="p">,</span> <span class="s2">&quot;lae&quot;</span><span class="p">,</span> <span class="s2">&quot;huber&quot;</span><span class="p">,</span> <span class="s2">&quot;fair&quot;</span><span class="p">,</span>
                                                    <span class="s2">&quot;log_cosh&quot;</span><span class="p">,</span> <span class="s2">&quot;tweedie&quot;</span><span class="p">],</span>
                                                       <span class="n">descr</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">task_type</span> <span class="o">==</span> <span class="n">consts</span><span class="o">.</span><span class="n">CLASSIFICATION</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">objective</span> <span class="o">!=</span> <span class="s2">&quot;cross_entropy&quot;</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;objective param&#39;s objective </span><span class="si">{}</span><span class="s2"> not supported&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">objective</span><span class="p">))</span>

        <span class="k">elif</span> <span class="n">task_type</span> <span class="o">==</span> <span class="n">consts</span><span class="o">.</span><span class="n">REGRESSION</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">objective</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">objective</span><span class="p">,</span>
                                                               <span class="p">[</span><span class="s2">&quot;lse&quot;</span><span class="p">,</span> <span class="s2">&quot;lae&quot;</span><span class="p">,</span> <span class="s2">&quot;huber&quot;</span><span class="p">,</span> <span class="s2">&quot;fair&quot;</span><span class="p">,</span> <span class="s2">&quot;log_cosh&quot;</span><span class="p">,</span> <span class="s2">&quot;tweedie&quot;</span><span class="p">],</span>
                                                               <span class="n">descr</span><span class="p">)</span>

            <span class="n">params</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">objective</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;huber&quot;</span><span class="p">,</span> <span class="s2">&quot;fair&quot;</span><span class="p">,</span> <span class="s2">&quot;tweedie&quot;</span><span class="p">]:</span>
                <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">params</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s1">&#39;list&#39;</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">params</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s2">&quot;objective param&#39;s params </span><span class="si">{}</span><span class="s2"> not supported, should be non-empty list&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">params</span><span class="p">))</span>

                <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">params</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;objective param&#39;s params[0] </span><span class="si">{}</span><span class="s2"> not supported&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">objective</span> <span class="o">==</span> <span class="s1">&#39;tweedie&#39;</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">params</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">params</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="mi">2</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;in tweedie regression, objective params[0] should betweend [1, 2)&quot;</span><span class="p">)</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">objective</span> <span class="o">==</span> <span class="s1">&#39;fair&#39;</span> <span class="ow">or</span> <span class="s1">&#39;huber&#39;</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">params</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="mf">0.0</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;in </span><span class="si">{}</span><span class="s2"> regression, objective params[0] should greater than 0.0&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">objective</span><span class="p">))</span>
        <span class="k">return</span> <span class="kc">True</span></div></div>


<div class="viewcode-block" id="DecisionTreeParam"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.boosting_tree_param.DecisionTreeParam">[docs]</a><span class="k">class</span> <span class="nc">DecisionTreeParam</span><span class="p">(</span><span class="n">BaseParam</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Define decision tree parameters that used in federated ml.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    criterion_method : str, accepted &quot;xgboost&quot; only, the criterion function to use, default: &#39;xgboost&#39;</span>

<span class="sd">    criterion_params: list, should be non empty and first element is float-number, default: 0.1.</span>

<span class="sd">    max_depth: int, positive integer, the max depth of a decision tree, default: 5</span>

<span class="sd">    min_sample_split: int, least quantity of nodes to split, default: 2</span>

<span class="sd">    min_impurity_split: float, least gain of a single split need to reach, default: 1e-3</span>

<span class="sd">    min_leaf_node: int, when samples no more than min_leaf_node, it becomes a leave, default: 1</span>

<span class="sd">    max_split_nodes: int, positive integer, we will use no more than max_split_nodes to</span>
<span class="sd">                      parallel finding their splits in a batch, for memory consideration. default is 65536</span>

<span class="sd">    n_iter_no_change: bool, accepted True,False only, if set to True, tol will use to consider</span>
<span class="sd">                      stop tree growth. default: True</span>

<span class="sd">    feature_importance_type: str, support &#39;split&#39;, &#39;gain&#39; only.</span>
<span class="sd">                             if is &#39;split&#39;, feature_importances calculate by feature split times,</span>
<span class="sd">                             if is &#39;gain&#39;, feature_importances calculate by feature split gain.</span>
<span class="sd">                             default: &#39;split&#39;</span>

<span class="sd">    tol: float, only use when n_iter_no_change is set to True, default: 0.001</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">criterion_method</span><span class="o">=</span><span class="s2">&quot;xgboost&quot;</span><span class="p">,</span> <span class="n">criterion_params</span><span class="o">=</span><span class="p">[</span><span class="mf">0.1</span><span class="p">],</span> <span class="n">max_depth</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
                 <span class="n">min_sample_split</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">min_imputiry_split</span><span class="o">=</span><span class="mf">1e-3</span><span class="p">,</span> <span class="n">min_leaf_node</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                 <span class="n">max_split_nodes</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">MAX_SPLIT_NODES</span><span class="p">,</span> <span class="n">feature_importance_type</span><span class="o">=</span><span class="s2">&quot;split&quot;</span><span class="p">,</span>
                 <span class="n">n_iter_no_change</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="mf">0.001</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">criterion_method</span> <span class="o">=</span> <span class="n">criterion_method</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">criterion_params</span> <span class="o">=</span> <span class="n">criterion_params</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">max_depth</span> <span class="o">=</span> <span class="n">max_depth</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">min_sample_split</span> <span class="o">=</span> <span class="n">min_sample_split</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">min_impurity_split</span> <span class="o">=</span> <span class="n">min_imputiry_split</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">min_leaf_node</span> <span class="o">=</span> <span class="n">min_leaf_node</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">max_split_nodes</span> <span class="o">=</span> <span class="n">max_split_nodes</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">feature_importance_type</span> <span class="o">=</span> <span class="n">feature_importance_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">n_iter_no_change</span> <span class="o">=</span> <span class="n">n_iter_no_change</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tol</span> <span class="o">=</span> <span class="n">tol</span>

<div class="viewcode-block" id="DecisionTreeParam.check"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.boosting_tree_param.DecisionTreeParam.check">[docs]</a>    <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">descr</span> <span class="o">=</span> <span class="s2">&quot;decision tree param&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">criterion_method</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">criterion_method</span><span class="p">,</span>
                                                             <span class="p">[</span><span class="s2">&quot;xgboost&quot;</span><span class="p">],</span>
                                                             <span class="n">descr</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">criterion_params</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s2">&quot;list&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decision tree param&#39;s criterion_params </span><span class="si">{}</span><span class="s2"> not supported, should be list&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">criterion_params</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">criterion_params</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decisition tree param&#39;s criterio_params should be non empty&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">criterion_params</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">,</span> <span class="s2">&quot;float&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decision tree param&#39;s criterion_params element shoubld be numeric&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_depth</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decision tree param&#39;s max_depth </span><span class="si">{}</span><span class="s2"> not supported, should be integer&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">max_depth</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_depth</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decision tree param&#39;s max_depth should be positive integer, no less than 1&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">min_sample_split</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decision tree param&#39;s min_sample_split </span><span class="si">{}</span><span class="s2"> not supported, should be integer&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">min_sample_split</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">min_impurity_split</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">,</span> <span class="s2">&quot;float&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decision tree param&#39;s min_impurity_split </span><span class="si">{}</span><span class="s2"> not supported, should be numeric&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">min_impurity_split</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">min_leaf_node</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decision tree param&#39;s min_leaf_node </span><span class="si">{}</span><span class="s2"> not supported, should be integer&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">min_leaf_node</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_split_nodes</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_split_nodes</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decision tree param&#39;s max_split_nodes </span><span class="si">{}</span><span class="s2"> not supported, &quot;</span> <span class="o">+</span> \
                             <span class="s2">&quot;should be positive integer between 1 and </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_split_nodes</span><span class="p">,</span>
                                                                                  <span class="n">consts</span><span class="o">.</span><span class="n">MAX_SPLIT_NODES</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">n_iter_no_change</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s2">&quot;bool&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decision tree param&#39;s n_iter_no_change </span><span class="si">{}</span><span class="s2"> not supported, should be bool type&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">n_iter_no_change</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tol</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decision tree param&#39;s tol </span><span class="si">{}</span><span class="s2"> not supported, should be numeric&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tol</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">feature_importance_type</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">feature_importance_type</span><span class="p">,</span>
                                                                    <span class="p">[</span><span class="s2">&quot;split&quot;</span><span class="p">,</span> <span class="s2">&quot;gain&quot;</span><span class="p">],</span>
                                                                    <span class="n">descr</span><span class="p">)</span>

        <span class="k">return</span> <span class="kc">True</span></div></div>


<div class="viewcode-block" id="BoostingTreeParam"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.boosting_tree_param.BoostingTreeParam">[docs]</a><span class="k">class</span> <span class="nc">BoostingTreeParam</span><span class="p">(</span><span class="n">BaseParam</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Define boosting tree parameters that used in federated ml.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    task_type : str, accepted &#39;classification&#39;, &#39;regression&#39; only, default: &#39;classification&#39;</span>

<span class="sd">    tree_param : DecisionTreeParam Object, default: DecisionTreeParam()</span>

<span class="sd">    objective_param : ObjectiveParam Object, default: ObjectiveParam()</span>

<span class="sd">    learning_rate : float, accepted float, int or long only, the learning rate of secure boost. default: 0.3</span>

<span class="sd">    num_trees : int, accepted int, float only, the max number of trees to build. default: 5</span>

<span class="sd">    subsample_feature_rate : float, a float-number in [0, 1], default: 0.8</span>

<span class="sd">    n_iter_no_change : bool,</span>
<span class="sd">        when True and residual error less than tol, tree building process will stop. default: True</span>

<span class="sd">    encrypt_param : EncodeParam Object, encrypt method use in secure boost, default: EncryptParam()</span>

<span class="sd">    quantile_method : str, accepted &#39;bin_by_sample_data&#39; or &#39;bin_by_data_block&#39; only,</span>
<span class="sd">                      the quantile method use in secureboost, default: &#39;bin_by_sample_data&#39;</span>

<span class="sd">    bin_num: int, positive integer greater than 1, bin number use in quantile. default: 32</span>

<span class="sd">    bin_gap: float, least difference between bin points, default: 1e-3</span>

<span class="sd">    bin_sample_num: int, if quantile method is &#39;bin_by_sample_data&#39;, max amount of samples to find bins.</span>
<span class="sd">                    default: 10000</span>

<span class="sd">    encrypted_mode_calculator_param: EncryptedModeCalculatorParam object, the calculation mode use in secureboost,</span>
<span class="sd">                                     default: EncryptedModeCalculatorParam()</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tree_param</span><span class="o">=</span><span class="n">DecisionTreeParam</span><span class="p">(),</span> <span class="n">task_type</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">CLASSIFICATION</span><span class="p">,</span>
                 <span class="n">objective_param</span><span class="o">=</span><span class="n">ObjectiveParam</span><span class="p">(),</span>
                 <span class="n">learning_rate</span><span class="o">=</span><span class="mf">0.3</span><span class="p">,</span> <span class="n">num_trees</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">subsample_feature_rate</span><span class="o">=</span><span class="mf">0.8</span><span class="p">,</span> <span class="n">n_iter_no_change</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                 <span class="n">tol</span><span class="o">=</span><span class="mf">0.0001</span><span class="p">,</span> <span class="n">encrypt_param</span><span class="o">=</span><span class="n">EncryptParam</span><span class="p">(),</span> <span class="n">quantile_method</span><span class="o">=</span><span class="s2">&quot;bin_by_sample_data&quot;</span><span class="p">,</span>
                 <span class="n">bin_num</span><span class="o">=</span><span class="mi">32</span><span class="p">,</span> <span class="n">bin_gap</span><span class="o">=</span><span class="mf">1e-3</span><span class="p">,</span> <span class="n">bin_sample_num</span><span class="o">=</span><span class="mi">10000</span><span class="p">,</span>
                 <span class="n">encrypted_mode_calculator_param</span><span class="o">=</span><span class="n">EncryptedModeCalculatorParam</span><span class="p">(),</span>
                 <span class="n">predict_param</span><span class="o">=</span><span class="n">PredictParam</span><span class="p">(),</span> <span class="n">cv_param</span><span class="o">=</span><span class="n">CrossValidationParam</span><span class="p">()):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tree_param</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">tree_param</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">task_type</span> <span class="o">=</span> <span class="n">task_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">objective_param</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">objective_param</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">learning_rate</span> <span class="o">=</span> <span class="n">learning_rate</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">num_trees</span> <span class="o">=</span> <span class="n">num_trees</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">subsample_feature_rate</span> <span class="o">=</span> <span class="n">subsample_feature_rate</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">n_iter_no_change</span> <span class="o">=</span> <span class="n">n_iter_no_change</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tol</span> <span class="o">=</span> <span class="n">tol</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">encrypt_param</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">encrypt_param</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">quantile_method</span> <span class="o">=</span> <span class="n">quantile_method</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bin_num</span> <span class="o">=</span> <span class="n">bin_num</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bin_gap</span> <span class="o">=</span> <span class="n">bin_gap</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bin_sample_num</span> <span class="o">=</span> <span class="n">bin_sample_num</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">encrypted_mode_calculator_param</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">encrypted_mode_calculator_param</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">predict_param</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">predict_param</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cv_param</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">cv_param</span><span class="p">)</span>

<div class="viewcode-block" id="BoostingTreeParam.check"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.boosting_tree_param.BoostingTreeParam.check">[docs]</a>    <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tree_param</span><span class="o">.</span><span class="n">check</span><span class="p">()</span>

        <span class="n">descr</span> <span class="o">=</span> <span class="s2">&quot;boosting tree param&#39;s&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">task_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="n">consts</span><span class="o">.</span><span class="n">CLASSIFICATION</span><span class="p">,</span> <span class="n">consts</span><span class="o">.</span><span class="n">REGRESSION</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;boosting tree param&#39;s task_type </span><span class="si">{}</span><span class="s2"> not supported, should be </span><span class="si">{}</span><span class="s2"> or </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">task_type</span><span class="p">,</span> <span class="n">consts</span><span class="o">.</span><span class="n">CLASSIFICATION</span><span class="p">,</span> <span class="n">consts</span><span class="o">.</span><span class="n">REGRESSION</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">objective_param</span><span class="o">.</span><span class="n">check</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">task_type</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">learning_rate</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;boosting tree param&#39;s learning_rate </span><span class="si">{}</span><span class="s2"> not supported, should be numeric&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">learning_rate</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">num_trees</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_trees</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;boosting tree param&#39;s num_trees </span><span class="si">{}</span><span class="s2"> not supported, should be postivie integer&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">num_trees</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">subsample_feature_rate</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]</span> <span class="ow">or</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">subsample_feature_rate</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">subsample_feature_rate</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;boosting tree param&#39;s subsample_feature_rate should be a numeric number between 0 and 1&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">n_iter_no_change</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s2">&quot;bool&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;boosting tree param&#39;s n_iter_no_change </span><span class="si">{}</span><span class="s2"> not supported, should be bool type&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">n_iter_no_change</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tol</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;boosting tree param&#39;s tol </span><span class="si">{}</span><span class="s2"> not supported, should be numeric&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tol</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">encrypt_param</span><span class="o">.</span><span class="n">check</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">quantile_method</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">quantile_method</span><span class="p">,</span>
                                                             <span class="p">[</span><span class="s2">&quot;bin_by_data_block&quot;</span><span class="p">,</span> <span class="s2">&quot;bin_by_sample_data&quot;</span><span class="p">],</span>
                                                             <span class="s2">&quot;boosting tree param&#39;s quantile_method&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bin_num</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_num</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;boosting tree param&#39;s bin_num </span><span class="si">{}</span><span class="s2"> not supported, should be positive integer greater than 1&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">bin_num</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bin_gap</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;boosting tree param&#39;s bin_gap </span><span class="si">{}</span><span class="s2"> not supported, should be numeric&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bin_gap</span><span class="p">))</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">quantile_method</span> <span class="o">==</span> <span class="s2">&quot;bin_by_sample_data&quot;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bin_sample_num</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">,</span> <span class="s2">&quot;long&quot;</span><span class="p">]</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_sample_num</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;boosting tree param&#39;s sample_num </span><span class="si">{}</span><span class="s2"> not supported, should be positive integer&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">bin_sample_num</span><span class="p">))</span>

        <span class="k">return</span> <span class="kc">True</span></div></div>



</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, FATE_TEAM

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>